<?php

/* * ***********************************************************************
  Class Category
  ----------------------------------------------------------------
  PICKCO CMS Project
  Company: PICKCO  Co., Ltd
  Email: admin@pick.vn
  Last updated: 15/07/2008
 * ************************************************************************ */

class Pick_Core_Logs extends Pick_Core_Objects {

    private $infoLogs; // Log info

    function Pick_Core_Logs($database = '') {
        if (!$database) {
            global $db;
            $this->_db = $db;
        } else
            $this->_db = $database;
        $this->objectInfo = "Pick_Core_LogsInfo";
        $this->table = DB_PREFIX . "logs";
    }

    function start() {
        $ip = Pick_Http_Ip::getIp();
        $objLogs = $this->getObjectFromIp($ip);
        if (empty($objLogs)) {
            $logsInfo = new Pick_Core_LogsInfo();
            $objLang = new Pick_Core_Languages();
            $lang = $objLang->getDefaultLanguage();
            $logsInfo->setField('ip', $ip);
            $logsInfo->setField('lang', $lang);
            $this->add($logsInfo->getArrayField());
            $this->infoLogs = $logsInfo;
        } else {
            $this->infoLogs = $objLogs;
        }
    }

    function setLangClient($lang){
        $this->infoLogs->setField('lang', $lang);
    }

    function getLangClient(){
        return $this->infoLogs->getField('lang');
    }

    function update() {
        $fields = $this->infoLogs->getArrayField();
        parent::update($fields, "`ip` = '".$this->infoLogs->getField('ip')."'");
    }

    function getObjectFromIP($ip = '') {
        if ($ip != '') {
            $object = $this->getObjects(1, "`ip` = '$ip'" . ' AND status = 1');
            if (is_array($object))
                return $object['data'][0];
        }
        return '';
    }

    /* -----------------------------------------------------------------------*
     * Function: cleanTrash xóa tất cả chuyên mục và mẫu tin trong chuyên mục co trang thai la 2
     * Parameter: WHERE catproduct
     * Return:array ID
     * ----------------------------------------------------------------------- */

    function cleanTrash($condition = '1=1') {
        $dem = 0;
        $this->delete($condition . ' AND status = 2');
        return true;
    }

}

?>